// 源插件
import React, { PureComponent, Fragment } from 'react';
import { connect } from 'dva';
import moment from 'moment';
import router from 'umi/router';
import { NumberDivide, DateDiff, FormatnumberZero, Mover, DateStamp } from '@/function.js';

// 视图插件
import {
  BackTop,
  Empty,
  Spin,
  Row,
  Col,
  Card,
  Form,
  Input,
  Select,
  Icon,
  Button,
  Dropdown,
  Menu,
  InputNumber,
  DatePicker,
  Modal,
  message,
  Badge,
  Divider,
  Steps,
  Radio,
  Upload,
} from 'antd';
import StandardTablePro from '@/components/UpgradeStandardTable/StandardTablePro';

// 外部组件
import StandardTable from '@/components/StandardTable';
import PageHeaderWrapper from '@/components/PageHeaderWrapper';
import Loading from '@/components/Loading/Loading';

// css OR less预编译器
import styles from './All.less';

// 图片

/**
 *  Describe:数据连接
 *  Created by xjc on 2019/5/15
 */

@connect(({ fourfunds, loading }) => ({
  fourfunds,
  loading: loading.models.fourfundsRule,
}))
@Form.create()
class DayFundanalysis extends PureComponent {
  componentWillMount() {}

  /**
   *  Describe:当前状态
   *  Created by xjc on 2019/5/15
   */

  state = {
    listLoading: false, // 加载状态
    selectedRows: [], // 选择行
    formValues: {
      num: 10,
      page: 1,
    }, // 表格参数
    /* pageValues:{current: 1, pageSize: 10, total: 0}, */
    StocksDetailVisible: false, // modal开关
    OptionVisible: false, // modal开关
    record: {}, // 当前行内容
    searchText: '', // 搜索内容
    columns: [], // 表头处理结果
    dataSource: {
      data: [],
      total: [],
      code: 0,
    },
  };

  dataSourceChange() {
    const { dispatch } = this.props;
    const that = this;
    dispatch({
      type: 'fourfunds/GetFundLastDayInfo',
      payload: {},
      callback: res => {
        const { data } = res;
        that.setState({
          dataSource: {
            title: `四号基金账户汇总表 ${data.stock.date.split(' ')[0]} 汇总表`,
            total: [],
            titleTotal: false,
            data: [
              {
                name: '个股',
                marketvalue: data.stock.marketvalue,
                positionprofit: data.stock.onhandprofit,
                dayprofit: data.stock.todayprofit,
                historyprofit: data.stock.historyprofit,
                premiumscollect: data.stock.pendingpremium,
                profit: data.stock.profit,
                profitmarket: data.stock.profitratio,
                profitpercent: data.stock.profitpercent,
                positionpercent: data.stock.positionpercent,
                highpremiums: data.stock.highpremium,
              },
              {
                name: 'Sell Call',
                marketvalue: data.sc.marketvalue,
                positionprofit: data.sc.onhandprofit,
                dayprofit: data.sc.todayprofit,
                historyprofit: data.sc.historyprofit,
                premiumscollect: data.sc.pendingpremium,
                profit: data.sc.profit,
                profitmarket: data.sc.profitratio,
                profitpercent: data.sc.profitpercent,
                positionpercent: data.sc.positionpercent,
                highpremiums: data.sc.highpremium,
              },
              {
                name: 'Sell Put',
                marketvalue: data.sp.marketvalue,
                positionprofit: data.sp.onhandprofit,
                dayprofit: data.sp.todayprofit,
                historyprofit: data.sp.historyprofit,
                premiumscollect: data.sp.pendingpremium,
                profit: data.sp.profit,
                profitmarket: data.sp.profitratio,
                profitpercent: data.sp.profitpercent,
                positionpercent: data.sp.positionpercent,
                highpremiums: data.sp.highpremium,
              },
              {
                name: '总计：',
                marketvalue: data.sum.marketvalue,
                positionprofit: data.sum.onhandprofit,
                dayprofit: data.sum.todayprofit,
                historyprofit: data.sum.historyprofit,
                premiumscollect: data.sum.pendingpremium,
                profit: data.sum.profit,
                profitmarket: data.sum.profitratio,
                profitpercent: data.sum.profitpercent,
                positionpercent: data.sum.positionpercent,
                highpremiums: data.sum.highpremium,
              },
            ],
            code: res.code,
            columns: [
              {
                title: '',
                width: 80,
                dataIndex: 'name',
                type: 'string',
              },
              {
                title: '市值',
                width: 80,
                type: 'number',
                dataIndex: 'marketvalue',
              },
              {
                title: '持仓盈亏',
                width: 80,
                type: 'number',
                dataIndex: 'positionprofit',
              },
              {
                title: '当日盈亏',
                width: 80,
                type: 'number',
                dataIndex: 'dayprofit',
              },
              {
                title: '历史累计盈亏',
                width: 80,
                type: 'number',
                dataIndex: 'historyprofit',
              },
              {
                title: '待收权利金',
                width: 80,
                type: 'number',
                dataIndex: 'premiumscollect',
              },
              {
                title: '持仓+历史总收益',
                width: 110,
                type: 'number',
                dataIndex: 'profit',
              },
              {
                title: '盈利市值比',
                width: 80,
                type: 'number',
                dataIndex: 'profitmarket',
                render: (value, row, index) => {
                  return value === null ? null : (
                    <span>{NumberDivide(mathService.mul(value, 100), null, '%')}</span>
                  );
                },
              },
              {
                title: '总盈利百分比',
                width: 80,
                type: 'number',
                dataIndex: 'profitpercent',
                render: (value, row, index) => {
                  return value === null ? null : (
                    <span>{NumberDivide(mathService.mul(value, 100), null, '%')}</span>
                  );
                },
              },
              {
                title: '仓位占比',
                width: 80,
                type: 'number',
                dataIndex: 'positionpercent',
                render: (value, row, index) => {
                  return value === null ? null : (
                    <span>{NumberDivide(mathService.mul(value, 100), null, '%')}</span>
                  );
                },
              },
              {
                title: '高权利金',
                width: 80,
                type: 'number',
                dataIndex: 'highpremiums',
                render: (value, row, index) => {
                  return value === null ? null : (
                    <span>{NumberDivide(mathService.mul(value, 100), null, '%')}</span>
                  );
                },
              },
            ],
          },
        });
      },
    });
  }

  /**
   *  Describe:视图
   *  Created by xjc on 2019/5/15
   */

  render() {
    const { dataSource } = this.state;

    return (
      <PageHeaderWrapper>
        <Card>
          <div>
            <StandardTablePro dataSource={dataSource} />
          </div>
        </Card>
      </PageHeaderWrapper>
    );
  }

  componentDidMount() {
    this.dataSourceChange();
  }

  componentWillUnmount() {}
}

export default DayFundanalysis;
